// JavaScript Document
var userAgent = navigator.userAgent.toLowerCase();
function get_browser() {
	var b;
	if (window.ActiveXObject) {
		v = userAgent.substr(userAgent.indexOf('msie') + 5, 3);
		b = 'ie';
	} else if (userAgent.indexOf("firefox") != - 1) {
		v = userAgent.substr(userAgent.indexOf('gecko/') + 6, 8);
		b = 'firefox';
	} else if (userAgent.indexOf("safari") != - 1) {
		v = -1;
		b = 'safari';
	} else if (userAgent.indexOf("opera") != - 1) {
		v = opera.version();
		b = 'opera';
	} else {
		v = -1;
		b = -1;
	}

	return {
		name : b,
		version: v
	};
}

var browser = get_browser();

function CreateEl(t,c,i){
		var x=document.createElement(t);
		x.className=c;
		x.id=i;
		x.style.display="block";
		return(x);
}

function formatfloat(f,size){  
	var tf=f*Math.pow(10,size);  
	tf=Math.round(tf+0.000000001);  
	tf=tf/Math.pow(10,size); 
	return tf;  
}  

function html2text(text){
   text = text.replace(/&/g, "&amp;") ;
   text = text.replace(/"/g, "&quot;") ;
   text = text.replace(/</g, "&lt;") ;
   text = text.replace(/>/g, "&gt;") ;
   text = text.replace(/'/g, "&#146;") ;
   text = text.replace(/\n/g,"<br/>");
   text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
   text = text.replace(/(^\s+)|(\s+$)/g,"");
   return text;
}

function trim(text){
        text = text.replace(/(^\s+)|(\s+$)/g,"");
        return text;
}


function chineseTest(test){
	 var re=/^[\u4e00-\u9fa5]+$/;
	 return re.test(test);	
}

function EnglishTest(test){
	 var re=/^[a-zA-Z]+$/;
	 return re.test(test);	
}

function EnglishAndChineseTest(test){
	 var re=/^[a-zA-Z\u4e00-\u9fa5]+$/;
	 return re.test(test);	
}

function wordTest(test){
	 var re=/^[a-zA-Z\u4e00-\u9fa50-9\s]+$/;
	 return re.test(test);
}

function numTest(test){
	 var re=/^[0-9]+$/;
	 return re.test(test);			
}

function checkEmail(test){
	 var re=/^[0-9a-zA-Z\-_\.]+@[0-9a-zA-Z\-_]+\.[a-zA-Z]+\.*[a-zA-Z]*$/;
	 return re.test(test);	
}

function notSpecialWord(test){
	 var re=/^[a-zA-Z\u4e00-\u9fa50-9\s\-\.]+$/;
	 return re.test(test);	
}

function checkDateInput(test){
	 var re=/^\d\d\d\d\-\d{1,2}\-\d{1,2}$/;
	 return re.test(test);
}

function checkDateTimeInput(test){
	 var re=/^\d\d\d\d\-\d{1,2}\-\d{1,2}\s\d{}$/;
	 return re.test(test);
}

function firmTime(time){
     var re=/^\d\d\d\d\-((0\d)|(1[0-2]))\-(([0-2]\d)|(3[01]))\s(([01]\d)|(2[0-3])):[0-5]\d:[0-5]\d$/;
	 return re.test(time);
}

function checkIsImage(test){
	 var re=/\.(jpg)|(gif)|(bmp)|(png)|(jpeg)$/;
	 return re.test(test);		
}
function checkDecimal(test){
	var re=/(^[0-9]+$)|(^\d+[\.]\d+$)/;
	return re.test(test);		
}
function getViewportInfo() {     
     var w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;     
	 var h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;     
	 return {w:w,h:h}; 
}; 

function setOpacity(el){
		el.style.filter="alpha(opacity:70)";
		el.style.KHTMLOpacity="0.70";
		el.style.MozOpacity="0.70";
		el.style.opacity="0.70";
}


function showBack(){
	var id='';
	if(arguments[0]==''){
		id="thisToumingDiv";
	}else{
		id=arguments[0];
	}
	if(document.documentElement.scrollTop){
			var scrollpositionLeft=document.documentElement.scrollLeft;
			var scrollpositionTop=document.documentElement.scrollTop;
	}
	else{
			var scrollpositionLeft=document.body.scrollLeft;
			var scrollpositionTop=document.body.scrollTop;				
	}
	var thisToumingDiv=CreateEl("div","",id);
	var oWin=getViewportInfo();
	thisToumingDiv.style.position="absolute";
	thisToumingDiv.style.width="100%";
	thisToumingDiv.style.height=document.body.scrollHeight+"px";
	thisToumingDiv.style.left="0px";
	thisToumingDiv.style.top="0px";		
	thisToumingDiv.style.backgroundColor='#999999';
	setOpacity(thisToumingDiv);
	
	document.getElementsByTagName("body")[0].appendChild(thisToumingDiv);

}

function shutBack(){
	var id='';
	if(arguments[0]==''){
		id="thisToumingDiv";
	}else{
		id=arguments[0];
	}
	if(document.getElementById(id)){
		document.getElementsByTagName("body")[0].removeChild(document.getElementById(id));
	}
}


function getCenterDiv(width,height,left,top,id){
		var oWin=getViewportInfo();
		if(document.documentElement.scrollTop){
				var scrollpositionLeft=document.documentElement.scrollLeft;
				var scrollpositionTop=document.documentElement.scrollTop;
		}
		else{
				var scrollpositionLeft=document.body.scrollLeft;
				var scrollpositionTop=document.body.scrollTop;				
		}

		var thisTishiKuang=CreateEl("div","",id);
		thisTishiKuang.style.position="absolute";
		thisTishiKuang.style.width=width+"px";
		thisTishiKuang.style.height=height+"px";
		thisTishiKuang.style.backgroundColor='#fff';
		thisTishiKuang.style.display='none';
		

		thisTishiKuang.style.left=(oWin.w/2-left+scrollpositionLeft)+"px";
		thisTishiKuang.style.top=(oWin.h/2-top+scrollpositionTop)+"px";		
		
		thisTishiKuang.style.textAlign='center';
		thisTishiKuang.style.paddingTop='30px';
		thisTishiKuang.style.border='1px solid #000';
		
		return thisTishiKuang;
}

function showMsg(thismsg){
	
		var thisTishiKuang=getCenterDiv(350,80,175,35,'thisTishiKuang');
		
		showBack();
		
		document.getElementsByTagName("body")[0].appendChild(thisTishiKuang);
		
		$('#thisTishiKuang').fadeIn('slow');
		
		thisTishiKuang.innerHTML='<div align=center>'+thismsg+'</div><br /><div align=center><a onclick=shutMsg()><img src="'+ROOT_PATH+'/html/images/shutdown.gif" /></a></div>';
		
		$('select').css('visibility','hidden');
}

function shutMsg(){
		if(document.getElementById("thisTishiKuang")||document.getElementById("thisToumingDiv")){
				document.getElementsByTagName("body")[0].removeChild(document.getElementById("thisTishiKuang"));
				$('select').css('visibility','visible');
				shutBack();
		}
}

function alterMsg(msg){
		document.getElementById("thisTishiKuang").innerHTML='<div align=center>'+msg+'</div><br /><div align=center><a onclick=shutMsg()><img src="'+ROOT_PATH+'/html/images/shutdown.gif" /></a></div>';
}



function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}

function getRandom(length){
	var thisStr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var thisArray=thisStr.split("");
	var str=""
	for(var i=0;i<length;i++){
		str+=thisArray[getRandomNum(1,61)];
	
	}
	return str;
}

function Locate(e,thisId){
		var posx=0,posy=0;
		if(e==null) e=window.event;
		if(e.pageX || e.pageY){
    			posx=e.pageX; posy=e.pageY;
    	}
		else if(e.clientX || e.clientY){
    			if(document.documentElement.scrollTop){
        				posx=e.clientX+document.documentElement.scrollLeft;
        				posy=e.clientY+document.documentElement.scrollTop;
        		}
    			else{
        				posx=e.clientX+document.body.scrollLeft;
        				posy=e.clientY+document.body.scrollTop;
       			}
   	    }
		document.getElementById(thisId).style.top=(posy+10)+"px";
		document.getElementById(thisId).style.left=(posx-20)+"px";
}

function fGetXY(aTag)
{
    var oTmp = aTag;
    var pt = new Point(0,0);
    do 
    {
		if(browser.name=="ie"){
        	pt.x += oTmp.offsetLeft;
        	pt.y += oTmp.offsetTop;
		}
		else{
        	pt.x += oTmp.offsetLeft+"px";
        	pt.y += oTmp.offsetTop+"px";				
		}
        oTmp = oTmp.offsetParent;
    } while(oTmp.tagName!="BODY");
    return pt;
}

function Point(iX, iY)
{
    this.x = iX;
    this.y = iY;
}

function subStrs(text,thislength){
	if(text.length>thislength){
		return text.substring(0,thislength)+"..";
	}
	else{
		return text;	
	}
}

function selectAll(thisObject,formId,inputName){
	var thisForm=document.getElementById(formId);
	var inputArray=thisForm.getElementsByTagName('input');
	
	if(thisObject.checked==true){
		for(var i=0;i<inputArray.length;i++){
			if(inputArray[i].name==inputName){
				inputArray[i].checked=true;	
			}
		}
	}
	else{
		for(var i=0;i<inputArray.length;i++){
			if(inputArray[i].name==inputName){
				inputArray[i].checked=false;	
			}
		}
	}
}

function reverseSelect(){
	var objectNum=document.userdisplay.elements.length;
	objectNum=objectNum-3;
	for(var i=0;i<objectNum;i++){
		if(document.userdisplay.elements[i].checked==true){
			document.userdisplay.elements[i].checked=false;
		}
		else{
			document.userdisplay.elements[i].checked=true;
		}

	}
}


function setCookie(name,newvalue,path,domain,expire){
   var expireDate=new Date();
   expireDate.setTime(expireDate.getTime() + expire);
   if(domain==""){
    	domainString="";
   }
   else{
	   	domainString="domain="+domain+";";
   }
   document.cookie=name+"="+newvalue+";path="+path+";"+domainString+"expires="+expireDate.toGMTString();
}

function getCookie(name){
   var sRE="(?:; )?"+name+"=([^;]*);?";
   var oRE=new RegExp(sRE);
   
   if(oRE.test(document.cookie)){
        return decodeURIComponent(RegExp["$1"]);
   }
   else{
        return "";
   }
}

//复制功能
  function   copyToClipboard(txt)   {   
            if(window.clipboardData)   {   
                            //window.clipboardData.clearData();   
                            window.clipboardData.setData("Text",   txt);   
							alert("Successful reproduction！");
            }   else   if(navigator.userAgent.indexOf("Opera")   !=   -1)   {   
                      window.location   =   txt;   
            }   else   if   (window.netscape)   {   
                      try   {   
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
                      }   catch   (e)   {   
                                alert("被火狐瀏覽器拒絕！\n請在瀏覽器地址欄輸入'about:config'并回車\n然后將'signed.applets.codebase_principal_support'設置為'true', 並且建議使用IE瀏覽器!");   
                      }   
                      var   clip   =   Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
                      if   (!clip)   
                                return;   
                      var   trans   =   Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
                      if   (!trans)   
                                return;   
                      trans.addDataFlavor('text/unicode');   
                      var   str   =   new   Object();   
                      var   len   =   new   Object();   
                      var   str   =   Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
                      var   copytext   =   txt;   
                      str.data   =   copytext;   
                      trans.setTransferData("text/unicode",str,copytext.length*2);   
                      var   clipid   =   Components.interfaces.nsIClipboard;   
                      if   (!clip)   
                                return   false;   
                      clip.setData(trans,null,clipid.kGlobalClipboard);   
            }   
  }
  
function getDataBrowser(thisArray){
	var thisAjaxText="";
	if(thisArray[0].text){
		thisAjaxText=thisArray[0].text;
	}
	else{
		thisAjaxText=thisArray[0].textContent;	
	}
	return thisAjaxText;
}

function refreshItemYz(thisA){
	thisA.src=thisA.src.split('?').shift()+"?rand="+Math.random();
}

function shouldDel(){
	if(!confirm("Confirm to delete?")){
		return false;	
	}
	return true;
}
function checkShouldDelItems(formId,inputName,isparent){
	var thisForm=document.getElementById(formId);
	var flag=0;
	var inputArray=thisForm.getElementsByTagName('input');
	for(var i=0;i<inputArray.length;i++){
		if(inputArray[i].name==inputName){
			if(inputArray[i].checked==true){
				flag++;	
			}
		}
	}
	if(flag==0){
		if(isparent==1){
			parent.showMsg("No Select！");
		}else{
			showMsg("No Select！");	
		}
		return false;
	}
	else{
		if(confirm("Sure?")){
			return true;
		}
		else{
			return false;	
		}
	}	
}

function changeLanguage(){
	showMsg("<img src='"+ROOT_PATH+"/html/images/loading.gif' />");
	if(getCookie(COOKIE_PRE+'language')=="GB"){
		setCookie(COOKIE_PRE+'language','BIG5','/','',3600*24*365);
	}else if(getCookie(COOKIE_PRE+'language')=="BIG5"){
		setCookie(COOKIE_PRE+'language','GB','/','',3600*24*365);
	}else{
		setCookie(COOKIE_PRE+'language','BIG5','/','',3600*24*365);
	}
	window.location.reload();
}
var locationFl={
	inputid:'flid',
	getChildFenlei:function(thisSelect){
		$('#'+locationFl.inputid).val(0);
		$(thisSelect).after('<img id="flloading" style="margin-left:5px" src="html/images/fl_loading.gif" />');
		var pid=$(thisSelect).val();
		if(pid!=0){
			$.post(ROOT_PATH+"/shop-index-getlocationajax",{pid:pid},function(data) {
					$('#flloading').remove();
					eval("var flArray="+data);
					if(flArray.length!=0){
						var selectString=' <select onchange="locationFl.getChildFenlei(this);"><option value="0">please select the area</option>';
						for(var i=0;i<flArray.length;i++){
							selectString+="<option value="+flArray[i].flid+">"+flArray[i].flname+"</option>";
						}
						selectString+='</select> ';
						locationFl.removeSelect(thisSelect);
						$(thisSelect).after(selectString);
					}else{
						locationFl.removeSelect(thisSelect);
						$('#'+locationFl.inputid).val(pid);
					}
			});	
		}else{
			$('#flloading').remove();
			locationFl.removeSelect(thisSelect);
		}
	},
	removeSelect:function(thisSelect){
		if($(thisSelect).next().is('select')){
			var nextSelect=$(thisSelect).next();
			var removeSelect=new Array();
			removeSelect.push(nextSelect);
			while(nextSelect.next().is('select')){
				nextSelect=nextSelect.next();
				removeSelect.push(nextSelect);
			}
			for(var i in removeSelect){
				removeSelect[i].remove();
			}
		}			
	}
}

var userPmInfo={
	kuang:new Object(),
	innerHTML:"",
	sendTo:"",
	mustFlid:'',
	orderid:'',
	subject:'',
	caseitemid:'',
	show:function(){
		if(getCookie(COOKIE_PRE+"member_admin")==''){
			if(confirm("Do you want to login? Or you can't send messages!")){
				window.location.href=$('.login_action').attr('href');
			}
			return false;
		}
		this.createKuang();
		this.setKuangContent();
	},
	createKuang:function(){
		var thisPmKuang=getCenterDiv(800,480,350,240,'thisPmKuang');
		showBack('pmBackDiv');
		document.getElementsByTagName("body")[0].appendChild(thisPmKuang);
		$('#thisPmKuang').fadeIn('slow');
		$('#thisPmKuang').css('paddingTop','0px');
		$('#thisPmKuang').css('zIndex','100000');
		this.kuang=thisPmKuang;
	},
	shutKuang:function(){
		shutBack('pmBackDiv');
		$(this.kuang).remove();
	},
	setKuangContent:function(){
		var member_admin=getCookie(COOKIE_PRE+"member_admin");
		this.innerHTML='<div class="floatPmTop" style="height: 20px; width: 800px; padding-top: 10px;"><a style="float:right" onclick="userPmInfo.shutKuang();">close &nbsp;&nbsp;</a>Message Form</div>';
		this.innerHTML+='<div class="floatPmCenter" style="width: 800px;"><iframe width="800px" height="450px" src="'+member_admin+'-pm-add?fromto=to&flid=add&mustFlid='+this.mustFlid+'&sendto='+this.sendTo+'&orderid='+this.orderid+'&subject='+this.subject+'&caseitemid='+this.caseitemid+'"></iframe></div>';
		this.innerHTML+='<div class="floatPmBottom" style="width: 800px;"></div>';
		$(this.kuang).html(this.innerHTML);
		this.mustFlid='';
		this.sendTo='';
		this.orderid='';
		this.subject='';
		this.caseitemid='';
	}
}



var expressEffection={
	checkForm:function(lang){
		if($('select[name="from_station_'+lang+'"]').val()=='0'){
			alert('Please select which place you want to ship from!');
			return false;
		}
		if($('select[name="to_station_'+lang+'"]').val()=='0'){
			alert('Please select which place you want to ship to!');
			return false;
		}
		if(!checkDecimal($('input[name="weight"]').val())||$('input[name="weight"]').val()==0){
			alert('Please check the weight you just input!');
			return false;				
		}
		if($('input[name="size1"]').val()!=''||$('input[name="size2"]').val()!=''||$('input[name="size3"]').val()!=''){
			if(!checkDecimal($('input[name="size1"]').val())||!checkDecimal($('input[name="size2"]').val())||!checkDecimal($('input[name="size3"]').val())){
				alert('Please check the size you just input!');
				return false;		
			}
		}else{
			$('input[name="size1"]').val(0);
			$('input[name="size2"]').val(0);
			$('input[name="size3"]').val(0);
		}
		$('input[name="volume"]').val($('input[name="size1"]').val()+'*'+$('input[name="size2"]').val()+'*'+$('input[name="size3"]').val());
		$('#interExpress').submit();
	},
	changExpress:function(mode,carrier){
		if(mode=='1'){
			$('#firstDiv').css('display','none');
			$('#secondDiv').css('display','block');
			$('#CarriersDiv').html(carrier);
		}else{
			$('#firstDiv').css('display','block');
			$('#secondDiv').css('display','none');					
		}
	}
}

var countDown={
	trimTime:function(time){
		if(time<10){
			time='0'+time;	
		}
		return time;
	},
	setTimes:function(time){
		if(time<0){
			time=0;	
		}
		var hour=parseInt(time/3600);
		var minite=parseInt(time%3600/60);
		var seconds=parseInt(time%3600%60);
		return this.trimTime(hour)+":"+this.trimTime(minite)+":"+this.trimTime(seconds);
	}	
}
var userPannel={
	show:function(){
		$.post(ROOT_PATH+"/shop-index-userpanel",{},function(data) {
			userPannel.append(data);									  
		});
	},
	append:function(data){
		$('#loginPannel').html(data);
	}
}

var addComment = {
		kuang: new Object(),
		itemid: 0,
		orderid: 0,
		show:function(){	
			this.createKuang();
			this.setKuangContent();
		},
		createKuang:function(){
			var thisPmKuang=getCenterDiv(800,300,350,240,'thisPmKuang');
			showBack('pmBackDiv');
			document.getElementsByTagName("body")[0].appendChild(thisPmKuang);
			$('#thisPmKuang').fadeIn('slow');
			$('#thisPmKuang').css('paddingTop','0px');
			$('#thisPmKuang').css('zIndex','100000');
			this.kuang=thisPmKuang;
		},
		shutKuang:function(){
			shutBack('pmBackDiv');
			$(this.kuang).remove();
		},
		setKuangContent:function(){			
			this.innerHTML='<div class="floatPmTop" style="height: 20px; width: 800px; padding-top: 10px;"><a style="float:right" onclick="addComment.shutKuang();">close</a>Add Review</div>';
			this.innerHTML+='<div class="floatPmCenter"><iframe width="800px" height="300px" src="/adminb-order-addreview?orderid='+this.orderid+'&itemid='+this.itemid+'"></iframe></div>';
			this.innerHTML+='<div class="floatPmBottom"></div>';
			$(this.kuang).html(this.innerHTML);			
		}
	}

var GGSHOP = {};
GGSHOP.msgBox = {
    show: function(title, msg, width1, width2, height) {
            this.title = title;
            this.msg = msg;    
            this.floatback();
            var _width1 = '';
            var _width2 = '';
            var _height = '';
            if(!!width1){
            	_width1 = 'width:'+width1+'px;';
            }
            if(!!width2){
            	_width2 = 'style="width:'+width2+'px;"';
            }
            if(!!height){
            	_height = 'height:'+height+'px;';
            }
            this.content = $("<div class=\"fcj_blk0 w-blk-loading\" style=\""+_width1+" "+_height+" margin:10px; position:absolute; \"></\div>");
            this.content.html("<h2 class=\"blk0h2 f-iblk clearfix\"><span "+_width2+" class=\"spbg blkhdl\">"+this.title+"<\/span><span class=\"spbg blkhdr\"><div style=\"float: right; padding-top:5px; margin-right: 10px;cursor:pointer;\" onclick=\"GGSHOP.msgBox.hidden();\">close<\/div><\/span></h2>");
            this.content.html(this.content.html()+"<div class=\"blkbody\"><div class=\"inner-box\">"+this.msg+"<div style=\"margin:5px;text-align:center;\"><a onclick=\"GGSHOP.msgBox.hidden();\">Close</a></div><\/div><\/div>");    
            this.content.css({"left":($(window).width()-420)/2+"px", "top": $(document).scrollTop()+200, "z-index": 10001});
            this.content.appendTo($("body"));    
          },
    hidden: function() {
            this.content.remove();
            this.backdiv.remove();
          },
    msg: '',
    title: '',
    content: null,
    backdiv: null,
    floatback: function() {                            
            this.backdiv = $('<div></div>');
            this.backdiv.css({"width": $(window).width()+"px", "height": $(document).height()+"px","background": "#FFFFFF","opacity":0.5, "filter":"alpha(opacity=50)"});
            this.backdiv.css({"z-index": 10000, "position":"absolute", "top":"0px", "left":"0px"});
            this.backdiv.appendTo($("body"));
    }        
};

GGSHOP.loading = {
    show: function() {
        this.floatback();
        this.content = $("<div class=\"fcj_blk0 w-blk-loading\" style=\"margin:10px; position:absolute; top:380px; left:420px;\"></\div>");
        this.content.html("<h2 class=\"blk0h2 f-iblk clearfix\"><span class=\"spbg blkhdl\">Processing<\/span><span class=\"spbg blkhdr\"><\/span></h2>");
        this.content.html(this.content.html()+"<div class=\"blkbody\"><div class=\"inner-box\">Processing...<\/div><\/div>");    
        this.content.css({"left":($(window).width()-420)/2+"px", "top": $(document).scrollTop()+200, "z-index": 10001});
        this.content.appendTo($("body"));
    },
    content: null,
    backdiv: null,
    hidden: function() {
        this.content.remove();
        this.backdiv.remove();
    },
    floatback: function() {
            this.backdiv = $('<div></div>');
            this.backdiv.css({"width": $(window).width()+"px", "height": $(document).height()+"px","background": "#FFFFFF","opacity":0.5, "filter":"alpha(opacity=50)"});
            this.backdiv.css({"z-index": 10000, "position":"absolute", "top":"0px", "left":"0px"});
            this.backdiv.appendTo($("body"));
    }              
};

GGSHOP.clearcart = {
	clear: function() {
		$.ajax({
			type: "POST",
			url: "/product-clearcart",
			data: {},
			success: function(data) {
				switch(data) {					
					case "1":
						GGSHOP.msgBox.show('Success', 'Clear Success');
						window.location.href="/product-showitem";
						break;					
					default:						
						GGSHOP.msgBox.show('Error', 'error');
				}
			}			
		});
	}
}

GGSHOP.address = {
		toggle: function() {
			if ($('#address_edit_0').css('display') == 'none') {
				//$('#info').hide();	
				$('#address_edit_0').show();	
				$('.add-new-shipping').hide();
			} else {				
				$('#address_edit_0').hide();
			}
		},
		showEdit: function(id) {
			$('#address_'+id).hide();
			$('#address_edit_'+id).show();
		},
		hideEdit: function(id) {
			$('#address_edit_'+id).hide();
			$('#address_'+id).show();			
		},
		deleteAddress: function(id) {
			$('#info').hide();
			GGSHOP.loading.show();
			$.ajax({
				type: "get",
				url: "/product-deleteaddress?id="+id,
				data: {},
				success: function(data) {	
					$('#info').hide();	
					GGSHOP.loading.hidden();
					switch(data) {					
						case "1":
							GGSHOP.address.getAddress();
							break;					
						default:	
							alert(data);
							GGSHOP.msgBox.show('Error', 'error');
					}
				}			
			});
		},
		deleteAddress1: function(id) {
			$('#info').hide();
			GGSHOP.loading.show();
			$.ajax({
				type: "get",
				url: "/product-deleteaddress?id="+id,
				data: {},
				success: function(data) {	
					GGSHOP.loading.hidden();
					switch(data) {					
						case "1":
							GGSHOP.address.getAddress1();
							break;					
						default:	
							alert(data);
							GGSHOP.msgBox.show('Error', 'error');
					}
				}			
			});
		},
		getAddress: function(flag) {			
			GGSHOP.loading.show();			
			$.ajax({
				type: "get",
				url: "/product-getaddress",
				data: {},
				async: false,
				success: function(data) {	
					GGSHOP.loading.hidden();
					switch(data) {					
						case "1":
							GGSHOP.msgBox.show('Error', 'error');
							break;
						default:	
							$('#address_list').html(data);
							if (data == 0) {
								GGSHOP.address.toggle();
								$('.add-new-shipping').hide();
								$('#address_list').html('');
							}
					}
				}			
			});
		},
		getAddress1: function(flag) {			
			GGSHOP.loading.show();			
			$.ajax({
				type: "get",
				url: "/product-getaddress1",
				data: {},
				async: false,
				success: function(data) {	
					GGSHOP.loading.hidden();
					switch(data) {					
						case "1":
							GGSHOP.msgBox.show('Error', 'error');
							break;
						default:	
							$('#address_list').html(data);
							if (data == 0) {
								GGSHOP.address.toggle();
								$('.add-new-shipping').hide();
								$('#address_list').html('');
							}
					}
				}			
			});
		},
		flash:function(input,error){
			$(input).css('border','solid 2px red');
			$(input).css('color','red');
			$(input).val(error);
			$(input).attr('isError','1');
			$(input).click(function(){
				$(input).css('border','solid 1px #ccc');
				$(input).css('color','black');
				$(input).val('');
				$(this).unbind('click');
				$(input).attr('isError','0');
			});
		},
		check: function (id) {
			this.error = '';
			GGSHOP.loading.show();			
			var obj = $('#address_edit_'+id);
			var _input = obj.find("input[name='name']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {
				this.error = 'Please fill in your name.';
				this.flash(_input,this.error);
			}		
//			if (obj.find("input[name='zip']").val() == '') {				
//				this.error = this.error + '<br/> zip is Null';
//			}
			var _input = obj.find("input[name='address']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your address.';
				this.flash(_input,this.error);
			}
			var _input = obj.find("select[name='state']");
			if ($.trim(_input.val()) == 0|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your country.';
				this.flash(_input,this.error);
			}
			var _input = obj.find("input[name='city']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your city.';
				this.flash(_input,this.error);
			}
			var _input = obj.find("input[name='state1']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your state.';
				this.flash(_input,this.error);
			}
			var _input = obj.find("input[name='phone']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your phone.';
				this.flash(_input,this.error);
			}
			var _input = obj.find("input[name='post_code']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your post code.';
				this.flash(_input,this.error);
			}
			var _input = obj.find("input[name='email']");
			if ($.trim(_input.val()) == ''|| $(_input).attr('isError')=='1') {				
				this.error = 'Please fill in your email.';
				this.flash(_input,this.error);
			} else {
				var exp = new RegExp("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", "i");
				if (!exp.test(_input.val())) {
					this.error = 'Please fill in your email correctly.';
					this.flash(_input,this.error);
				}
			}
			GGSHOP.loading.hidden();
			if (this.error != '') {
				//GGSHOP.msgBox.hidden();
				return false;
			}
			return true;
		},
		confirmEdit: function(id) {				
			if (this.check(id) == true) {
				GGSHOP.loading.show();	
				var obj = $('#address_edit_'+id);	
				var name = obj.find("input[name='name']").val();
//				var zip = obj.find("input[name='zip']").val();
				var address = obj.find("input[name='address']").val();
				var state = obj.find("select[name='state']").val();
				var state1 = obj.find("input[name='state1']").val();
				var city = obj.find("input[name='city']").val();
				var phone = obj.find("input[name='phone']").val();
				var postCode = obj.find("input[name='post_code']").val();
				var email = obj.find("input[name='email']").val();
				$.ajax({
					type: "POST",
					url: "/product-updateaddress",
					data: {id: id, name: name, address: address, state: state, state1:state1, city: city, phone: phone, post_code: postCode, email: email},
					success: function(data) {	
						GGSHOP.loading.hidden();	
						switch(data) {					
							case "1":									
								GGSHOP.address.getAddress();								
								GGSHOP.address.setAddress(id);	
								break;
							default:
								GGSHOP.msgBox.show('Error', 'error');
						}
					}			
				});
			}			
		},
		confirmEdit1: function(id) {				
			if (this.check(id) == true) {
				GGSHOP.loading.show();	
				var obj = $('#address_edit_'+id);	
				var name = obj.find("input[name='name']").val();
//				var zip = obj.find("input[name='zip']").val();
				var address = obj.find("input[name='address']").val();
				var state = obj.find("select[name='state']").val();
				var state1 = obj.find("input[name='state1']").val();
				var city = obj.find("input[name='city']").val();
				var phone = obj.find("input[name='phone']").val();
				var postCode = obj.find("input[name='post_code']").val();
				var email = obj.find("input[name='email']").val();
				$.ajax({
					type: "POST",
					url: "/product-updateaddress",
					data: {id: id, name: name, address: address, state: state, state1:state1, city: city, phone: phone, post_code: postCode, email: email},
					success: function(data) {	
						GGSHOP.loading.hidden();	
						switch(data) {					
							case "1":									
								GGSHOP.address.getAddress1();								
								GGSHOP.address.setAddress1(id);	
								break;
							default:
								GGSHOP.msgBox.show('Error', 'error');
						}
					}			
				});
			}			
		},
//		setAddress: function(id) {
//			if (id == 0) {
//				if (this.check(id) == true) {
//					$('#add_new_address').submit();
//				}
//			} else {
//				window.location.href="/product-payorder?id="+id;
//			}
//		},
		setCurrent: function(id) {
			$('#address_'+id).css('background-color', '#e7e7e7');
			$('#address_'+id).find('input[type="button"]:first').val('SELECTED ADDRESS');
			$('#address_'+id).find('input[type="button"]:first').css('background', '#cccccc');
			$('#address_'+id).find('input[type="button"]:first').css('color', '#000');
		},
		setAddress: function(id) {			
			if (id == 0) {
				if (this.check(id) == true) {
					$('#info').hide();	
					GGSHOP.loading.show();
					var obj = $('#address_edit_'+id);	
					var name = obj.find("input[name='name']").val();
//					var zip = obj.find("input[name='zip']").val();
					var address = obj.find("input[name='address']").val();
					var state = obj.find("select[name='state']").val();
					var state1 = obj.find("input[name='state1']").val();
					var city = obj.find("input[name='city']").val();
					var phone = obj.find("input[name='phone']").val();
					var postCode = obj.find("input[name='post_code']").val();
					var addressExtra = obj.find("input[name='address_extra']").val();
					var email = obj.find("input[name='email']").val();
					
					if (obj.find("input[name='islog']").attr('checked')) {
						var isLog = 1;			
					} else {
						var isLog = 0;
					}
					$.ajax({
						type: "POST",
						url: "/product-payorder",
						data: {id: id, name: name, address: address, state: state, state1: state1, city: city, phone: phone, post_code: postCode, address_extra: addressExtra, email: email, islog: isLog},
						success: function(data) {	
							GGSHOP.loading.hidden();				
							switch(data) {		
								case "0":
									GGSHOP.msgBox.show('Error', 'Please Login In');
									break;
								case "1":
									GGSHOP.msgBox.show('Error', 'Please Full Input');
									break;
								case "2":
									GGSHOP.msgBox.show('Error', 'No Address');
									break;
								case "3":
									GGSHOP.msgBox.show('Error', 'Error Address');
									break;
								default:									
									GGSHOP.address.getAddress();										
									$('#address_edit_0').hide();
									$('.add-new-shipping').show();
									$('#info').show();	
									$('#info').html(data);	
									GGSHOP.loading.hidden();
							}
						}			
					});					
				}
			} else {
				GGSHOP.loading.show();	
				$.ajax({
					type: "GET",
					url: "/product-payorder?id="+id,
					success: function(data) {	
						GGSHOP.loading.hidden();				
						switch(data) {		
							case "0":
								GGSHOP.msgBox.show('Error', 'Please Login In');
								break;
							case "1":
								GGSHOP.msgBox.show('Error', 'Please Full Input');
								break;
							case "2":
								GGSHOP.msgBox.show('Error', 'No Address');
								break;
							case "3":
								GGSHOP.msgBox.show('Error', 'Error Address');
								break;
							default:
								GGSHOP.address.getAddress();	
								GGSHOP.loading.hidden();
								$('#info').show();
								$('#info').html(data);								
						}
					}			
				});
			}
		},
		setAddress1: function(id) {			
			if (id == 0) {
				if (this.check(id) == true) {
					$('#info').hide();	
					GGSHOP.loading.show();
					var obj = $('#address_edit_'+id);	
					var name = obj.find("input[name='name']").val();
//					var zip = obj.find("input[name='zip']").val();
					var address = obj.find("input[name='address']").val();
					var state = obj.find("select[name='state']").val();
					var state1 = obj.find("input[name='state1']").val();
					var city = obj.find("input[name='city']").val();
					var phone = obj.find("input[name='phone']").val();
					var postCode = obj.find("input[name='post_code']").val();
					var addressExtra = obj.find("input[name='address_extra']").val();
					var email = obj.find("input[name='email']").val();
					
					if (obj.find("input[name='islog']").attr('checked')) {
						var isLog = 1;			
					} else {
						var isLog = 0;
					}
					$.ajax({
						type: "POST",
						url: "/product-payorder1",
						data: {id: id, name: name, address: address, state: state, state1: state1, city: city, phone: phone, post_code: postCode, address_extra: addressExtra, email: email, islog: isLog, orderid:$('input[name="orderid"]').val()},
						success: function(data) {	
							GGSHOP.loading.hidden();				
							switch(data) {		
								case "0":
									GGSHOP.msgBox.show('Error', 'Please Login In');
									break;
								case "1":
									GGSHOP.msgBox.show('Error', 'Please Full Input');
									break;
								case "2":
									GGSHOP.msgBox.show('Error', 'No Address');
									break;
								case "3":
									GGSHOP.msgBox.show('Error', 'Error Address');
									break;
								default:									
									GGSHOP.address.getAddress1();										
									$('#address_edit_0').hide();
									$('.add-new-shipping').show();
									$('#info').show();	
									$('#info').html(data);	
									GGSHOP.loading.hidden();
							}
						}			
					});					
				}
			} else {
				GGSHOP.loading.show();	
				$.ajax({
					type: "GET",
					url: "/product-payorder1?id="+id+"&orderid="+$('input[name="orderid"]').val(),
					success: function(data) {	
						GGSHOP.loading.hidden();				
						switch(data) {		
							case "0":
								GGSHOP.msgBox.show('Error', 'Please Login In');
								break;
							case "1":
								GGSHOP.msgBox.show('Error', 'Please Full Input');
								break;
							case "2":
								GGSHOP.msgBox.show('Error', 'No Address');
								break;
							case "3":
								GGSHOP.msgBox.show('Error', 'Error Address');
								break;
							default:
								GGSHOP.address.getAddress1();	
								GGSHOP.loading.hidden();
								$('#info').show();	
								$('#info').html(data);
						}
					}			
				});
			}
		},
		error: '',
		cancelAddress:function(){
			$('#address_edit_0').hide();
			$('.add-new-shipping').show();
			return false;
		}
};

GGSHOP.pay = {
		checkship: function() {
			var flag = 0;
			$('input[name="yunfeiid"]').each(function(){
				if ($(this).attr('checked') == true) {
					flag = 1;					
				}								
			});	
			if (flag == 0) {					
				return false;
			} else {
				return true;
			}
		},
		doship: function() {			
			if (this.checkship() == false) {
				GGSHOP.msgBox.show('Select a shipment', 'Please select a shipment');
				return;
			}
			$('#payform').submit();
		}
};

GGSHOP.product = {
	showCustom: function() {
		$("#producthtml").children().html("Show Products");
		$("#allproduct1").remove();
		
		$('#custom_size').css({"left":($(window).width()-785)/2+"px", "top": $(document).scrollTop()+100, "z-index": 10001});
		$('#custom_size').show();		
	},
	customHide: function() {
		$('#custom_size').hide();
	},
	removeParam: function(obj) {
		$(obj).parent().parent().remove();
		if ($('.custom-item-content').find('div[class="custom-item clearfix"]').length == 1) {
			$('.custom-item-content').find('div[class="custom-item clearfix"]:last').find(".custom-right").html('');
		}
	},
	addParam: function(obj) {
		//var _table_obj = $(obj).parent().parent();
		//var html = _table_obj.html();
		var _table_obj =  $('.custom-item-content');
		var html = $('.custom-item-content').find('div:first').html();
		$('.custom-item-content').find('div[class="custom-item clearfix"]:last').find(".custom-right").html('<input class="item-del spbg" type="button" name="delete" value="DELETE" />');
		$('.custom-item-content').find('div[class="custom-item clearfix"]:last').find('input[name="delete"]').click(function(){GGSHOP.product.removeParam(this);});
		//var thisIndex = '(\d+)';		
		reg = new RegExp("printorginal_(\\d+)", "g");
		html = html.replace(reg, 'printorginal_'+GGSHOP.product.printorginal_index);
	   
		reg = new RegExp("printorginal_select_(\\d+)", "g");
		html = html.replace(reg, 'printorginal_select_'+GGSHOP.product.printorginal_index);
		reg = new RegExp("printorginal_noselect_(\\d+)", "g");
		html = html.replace(reg, 'printorginal_noselect_'+GGSHOP.product.printorginal_index);
		if(GGSHOP.product.select_badgepatch_vars != null)
		{
			reg = new RegExp("select_badgepatch_tags_(\\d+)", "g");
			html = html.replace(reg, 'select_badgepatch_tags_'+GGSHOP.product.printorginal_index);
		}
		if(GGSHOP.product.select_Original_vars != null)
		{
			reg = new RegExp("select_Original_tags_(\\d+)", "g");
			html = html.replace(reg, 'select_Original_tags_'+GGSHOP.product.printorginal_index);
		}
		html = '<div class=\"custom-item clearfix\" style=\"border: none; padding: 0; background: none;\">'+html+'<\/div>';
		var _table_obj_clone = $(html);	
		_table_obj_clone.find("input[name^=printorginal_]").each(function(){			
			$(this).attr("name","printorginal_" + GGSHOP.product.printorginal_index);			
		});
		_table_obj_clone.find("input[name='printorginal_"+GGSHOP.product.printorginal_index+"']").each(function(){			
			if ($(this).val() == 1) {
				$(this).attr("checked","false");
			} else {
				$(this).attr("checked","true");
			}				
		});
		_table_obj_clone.find("input[type='text']").each(function(){
			$(this).attr("value",'');
		});
		_table_obj_clone.find('input[name="printshirtAmount[]"]').val(1);
		_table_obj_clone.find('input[name="printshirtNumCus[]"]').val('');
		_table_obj_clone.find('input[name="printshirtNameCus[]"]').val('');
		_table_obj_clone.find(".custom-right").html('<input class="item-del spbg" type="button" name="delete" value="DELETE" />');
		_table_obj_clone.find(".custom-right").find('input[name="delete"]').click(function(){GGSHOP.product.removeParam(this);});
		//_table_obj_clone.find(".custom-right").html('<input class="item-add spbg" type="button" name="add" value="ADD" onclick="GGSHOP.product.addParam(this);"/>')
		_table_obj.prepend(_table_obj_clone);
		//$(obj).parent().html('<input class="item-del spbg" type="button" name="delete" value="DELETE" onclick="$(this).parent().parent().remove();" />');
		if(GGSHOP.product.select_badgepatch_vars != null)
		{
			$('#select_badgepatch_tags_'+GGSHOP.product.printorginal_index).divSelect({data:GGSHOP.product.select_badgepatch_vars});
		}
		if(GGSHOP.product.select_Original_vars != null)
		{
			$('#select_Original_tags_'+GGSHOP.product.printorginal_index).divSelect({data:GGSHOP.product.select_Original_vars,callback:function(obj,v){
				GGSHOP.product.changeSelect(obj, v);
			}});
		}
		this.printorginal_index++;
	},
	addcart: function(){
		$('input[name="addNameNum"]').val(1);
		if (GGSHOP.product.check() == true) {
			$('#addtocartform').submit();
		}
		//this.customHide();
	},
	cancel: function() {
		$('input[name="addNameNum"]').val(0);
		this.customHide();
	},
	close: function() {
		if ($('input[name="addNameNum"]').val() == 1) {
			//if (confirm('You have choose custom size, are you sure clear?')) {
				$('input[name="addNameNum"]').val('0');
				$(".psize").each(function(){
					if ($(this).attr('org') == 1) {
						$(this).attr('org', '');
						$(this).val('0');
					} else {
						if ($(this).attr('org_val') > 0) {
							$(this).val($(this).attr('org_val'));
						}
					}
				});
				this.customHide();
			//}
		} else {
			this.customHide();
		}
	},
	check: function() {
		var minArray=$('input[name="min_counts[]"]');
		var maxArray=$('input[name="max_counts[]"]');
		var counts=0;
		var isTrue=true;
		
		var checkedNameNum= $('input[name="addNameNum"]').val();
		if(checkedNameNum != 0 && checkedNameNum != 1){
			GGSHOP.msgBox.show('ERROR', 'Please choose whether you want to print the name or number on the shirt!');
			return false;
		}
		var is_post = true;	
		$(".all_product").each(function(){
			if($(this).find("input[name='flag[]']").val()==1){
				if($(this).find("input[name='quantity[]']").val()==""){
					alert('Please fill in the quantity');
					$(this).find("input[name='quantity[]']").focus();
					is_post=false;
				}
			}
		});	
		if (checkedNameNum == 1) {
			$(".psize").each(function(){
				var size = $(this).attr("pv");
				var temp_obj_amount = 0;
				$("select[name='printshirtSize[]']").each(function(){
					if($(this).val() == size) {
						temp_obj_amount = parseInt($(this).parent().parent().find('input[name="printshirtAmount[]"]').val()) + temp_obj_amount;
						if ($(this).parent().parent().find('input[name="printshirtAmount[]"]').val() == 0 || $(this).parent().parent().find('input[name="printshirtAmount[]"]').val() == '') {
							alert("Please fill in the amount for size:" + size + ".");
							is_post = false;
							return false;
						}
						//检查是否选择配件型号
					}
				});
				if(temp_obj_amount > $(this).val()) {
					if ($(this).val() == 0 || $(this).val() == '') {
						$(this).attr('org', '1');						
					} else {
						$(this).attr('org_val', $(this).val()); //原始数据
					}
					$(this).val(temp_obj_amount);
					//GGSHOP.msgBox.show('ERROR', "The amount you total input is more than the size's total count you input for Size:" + size);
					//is_post = false;
					//return false;
				} else if (temp_obj_amount <= $(this).val()) {
					if ($(this).attr('org') == '1') {
						$(this).val(temp_obj_amount);
					} else {
						if (temp_obj_amount < $(this).attr('org_val')) {
							$(this).val($(this).attr('org_val'));
						}
					}
				}
			});
				
			if(is_post == false)
				return is_post;
			flagCustom = 0;
			flagOriginal = 0;
			flagBadge = 0;
			for(i=0;i<this.printorginal_index;i++) {
				$('input[name="printorginal_'+i+'"]').each(function(){					
					if ($(this).attr('checked') == 'checked') {						
						if ($(this).attr('value') == 0) {
							if ($(this).parent().find('input[name="printshirtNum[]"]').length > 0) {
								if ($(this).parent().find('input[name="printshirtNum[]"]').val() == '' ||
									$(this).parent().find('input[name="printshirtNum[]"]').val() == 0 ||
									$(this).parent().find('inputPlease fill in the amount for size[name="printshirtName[]"]').val() == '' ||
									$(this).parent().find('input[name="printshirtName[]"]').val() == 0) {
									flagCustom = 1;
								}
							}
						} else {							
							if ($(this).parent().find('select[name="Originalnum[]"]').val() == 0) {
								flagOriginal = 1;			//修改后这一步不用了											
							}	
							if ($(this).parent().prevAll('div').find('input[name="printshirtNumCus[]"]').length > 0)  {
								if ($(this).parent().prevAll('div').find('input[name="printshirtNumCus[]"]').val() == '' ||
									$(this).parent().prevAll('div').find('input[name="printshirtNumCus[]"]').val() == 0 ||
									$(this).parent().prevAll('div').find('input[name="printshirtNameCus[]"]').val() == '' ||
									$(this).parent().prevAll('div').find('input[name="printshirtNameCus[]"]').val() == 0) {
									flagOriginal = 2;														
								}
							}
						}
					}
					
					if ($(this).parent().parent().parent().find('input[name="select_badgepatch[]"]').length > 0) {
						if ($(this).parent().parent().parent().find('input[name="select_badgepatch[]"]').val() == '' ||
							$(this).parent().parent().parent().find('input[name="select_badgepatch[]"]').val() == 0) {
							flagBadge = 1;			
						}
					}
				})
				if ($('#select_badgepatch_tags_'+i).val() == '' || $('#select_badgepatch_tags_'+i).val() == 0) {
					flagBadge = 1;			
				}
			}

		}
		
		$('input[name="counts[]"]').each(
			function(){
				if(!numTest($(this).val())){
					isTrue=false;
				}else{
					counts+=parseInt($(this).val());
				}
			}
		);
		if(!isTrue){
			GGSHOP.msgBox.show('ERROR', 'Please enter the correct quantity you want to buy!');
			return false;
		}
		if(counts<parseInt($(minArray[0]).val())){	
			if (this.borderTimer == null) {
				this.borderTimer = setInterval(function(){GGSHOP.product.borderToggle()}, 600);
				$('input[name="counts[]"]').each(function(){
					$(this).click(function(){GGSHOP.product.clearBorderToggle();});
					$(this).css({'border':'1px #c0c0c0 solid'});
				});
			}
			//GGSHOP.msgBox.show('ERROR', 'The quantity you entered is too few!');
			return false;
		}
		if(counts>parseInt($(maxArray[maxArray.size()-1]).val())){
			GGSHOP.msgBox.show('ERROR', 'The quantity you entered is too many!');
			return false;
		}
		return is_post;
	},
	checkpack: function() {
		var counts = 0;
		$('input[class="psize"]').each(function(){
			counts += parseInt($(this).val());
		});
		if (counts > 0) {
			return true;
		}
		if (this.borderTimer == null) {
			this.borderTimer = setInterval(function(){GGSHOP.product.borderTogglePack()}, 600);
			$('input[name="counts[]"]').each(function(){
				$(this).click(function(){GGSHOP.product.clearBorderToggle();});
				$(this).css({'border':'1px #c0c0c0 solid'});
			});
		}
		//GGSHOP.msgBox.show('ERROR', 'The quantity you entered is too few!');
		return false;		
	},
	borderTogglePack: function() {
		if (this.borderToggleIndex <= 9) {
			if (this.borderToggleFlag == true) {				
				$('input[class="psize"]').each(function(){
					$(this).css({'border':'2px solid red'});			
				});
				GGSHOP.product.borderToggleFlag = false;
			} else {			
				$('input[class="psize"]').each(function(){
					$(this).css({'border':'1px #c0c0c0 solid'});			
				});
				GGSHOP.product.borderToggleFlag = true;
			}
			this.borderToggleIndex++;
		} else {
			this.borderToggleIndex = 0;
			clearInterval(this.borderTimer);
			this.borderTimer = null;
		}
	},
	borderToggle: function() {
		if (this.borderToggleIndex <= 9) {
			if (this.borderToggleFlag == true) {				
				$('input[name="counts[]"]').each(function(){
					$(this).css({'border':'2px solid red'});			
				});
				GGSHOP.product.borderToggleFlag = false;
			} else {			
				$('input[name="counts[]"]').each(function(){
					$(this).css({'border':'1px #c0c0c0 solid'});			
				});
				GGSHOP.product.borderToggleFlag = true;
			}
			this.borderToggleIndex++;
		} else {
			this.borderToggleIndex = 0;
			clearInterval(this.borderTimer);
			this.borderTimer = null;
		}
	},
	borderTimer: null,
	borderToggleFlag: true,
	borderToggleIndex: 0,
	printorginal_index: 1,
	clearBorderToggle: function(){
		this.borderToggleIndex = 0;
		clearInterval(this.borderTimer);
		this.borderTimer = null;
	},
	changeSelect: function(obj, str) {
		if (str != 0) {
			if (str.substr(0,1) == '#') {
				arr = str.split(' ');
				name = '';
				for (i=1;i<=arr.length-1;i++) {
					if (i==1) {
						name = arr[i];
					} else {
						name = name + ' ' + arr[i];
					}
				}
				$(obj).parent().prevAll('div').find('input[name="printshirtNumCus[]"]').val(arr[0]);
				$(obj).parent().prevAll('div').find('input[name="printshirtNameCus[]"]').val(name);	
			} else {
				arr = str.split('#');
				name = '';
				for (i=0;i<arr.length-1;i++) {
					if (i==0) {
						name = arr[i];
					} else {
						name = name + ' ' + arr[i];
					}
				}
				$(obj).parent().prevAll('div').find('input[name="printshirtNameCus[]"]').val(name);
				$(obj).parent().prevAll('div').find('input[name="printshirtNumCus[]"]').val('#'+arr[arr.length-1]);									
			}			
		} else {
			$(obj).parent().prevAll('div').find('input[name="printshirtNameCus[]"]').val('');
			$(obj).parent().prevAll('div').find('input[name="printshirtNumCus[]"]').val('');
		}
	},
	checkRadio: function(obj) {
		$(obj).parent().find('input[type="radio"]')[0].checked=true;
	}
};

GGSHOP.review = {
		get: function(page, id) {
			$.ajax({
				type: "GET",
				url: "/product-getreview?id="+id+"&page="+page,
				success: function(data) {
					$('#review_content').html(data);
				}			
			});
		}
};

GGSHOP.match = {
		chipin: function(teamId, matchId) {
			GGSHOP.loading.show();
			this.loadScore();
			GGSHOP.loading.hidden();
			this.show();
			this.teamId = teamId,
			this.matchId = matchId
		},
		teamId: 0,
		matchId: 0,
		show: function() {
			if ($('input[name="matchstatu"]').val() != 0) {
				GGSHOP.msgBox.show('ERROR', 'The match has stopped!');
				return false;
			}
			$('#jc_chipin').css({"left":($(window).width()-402)/2+"px", "top": $(document).scrollTop()+100, "z-index": 10000});
			$('#jc_chipin').show();	
		},
		hide: function() {
			this.itemId = 0;
			this.matchId = 0;
			$('#jc_chipin').hide();
		},
		bet: function() {
			if (this.teamId == 0 || this.matchId == 0) {
				GGSHOP.msgBox.show('ERROR', 'Please Choose a Team!');
				return false;
			}			
			betscore = $('#score').val();		
			reg = /^[1-9]\d*$/;			
			if (!reg.test(betscore)) {
				GGSHOP.msgBox.show('ERROR', 'Please Input Number!');
				return false;
			}
			GGSHOP.loading.show();
			$.ajax({
				type: "POST",
				url: "/match-chipin",
				data: {matchid: GGSHOP.match.matchId, teamid: GGSHOP.match.teamId, score: betscore},
				success: function(data) {
					GGSHOP.loading.hidden();
					switch(data) {					
						case "0":
							GGSHOP.msgBox.show('ERROR', 'Please Login First   <a href="\/auth-login?preurl=\/match-index-matchid='+$('input[name="matchid"]').val()+'">Login >><\/a>');
							break;
						case "1":
							GGSHOP.msgBox.show('ERROR', 'Your Score Is Not Enough');
							break;
						case "2":
							GGSHOP.msgBox.show('SUCCESS', 'Bet Success! If you win, we will contact you.');
							GGSHOP.match.loadScore();
							break;
						case "3":
							GGSHOP.msgBox.show('ERROR', 'Bet Faliure');
							break;
						default:
							alert(data);
					}					
					$('input[name="score"]').val('');
					GGSHOP.match.matchId = 0;
					GGSHOP.match.teamId = 0;
					GGSHOP.match.hide();
				}			
			});
		},
		loadScore: function() {				
			$.ajax({
				type: "get",
				url: "/match-getscore",			
				success: function(data) {	
					$('#my_score').html(data);
				}			
			});
		},
		addComment: function() {
			$.ajax({
				type: "POST",
				url: "/match-comment",	
				data: {content: $('#comment').val(), matchid: $('input[name="matchid"]').val()},
				success: function(data) {					
					switch (data) {
						case '0':
							GGSHOP.msgBox.show('ERROR', 'Please Login First   <a href="\/auth-login?preurl=\/match-index?matchid='+$('input[name="matchid"]').val()+'">Login >><\/a>');
							break;
						case '1':
							GGSHOP.msgBox.show('ERROR', 'Please Input Comments');
							break;
						case '2':
							GGSHOP.msgBox.show('ERROR', 'Success');
							GGSHOP.match.loadComment($('input[name="matchid"]').val());
							break;
						case '3':
							GGSHOP.msgBox.show('ERROR', 'Error');							
							break;
						default:
							alert('Error');
					}
				}			
			});
		},
		loadComment: function(matchId) {
			GGSHOP.loading.show();
			$.ajax({
				type: "get",
				url: "/match-getcomment?matchid="+matchId,					
				success: function(data) {					
					$('#list_comment').html(data);
				}			
			});
			GGSHOP.loading.hidden();
		}
};

GGSHOP.facematch = {
		addComment: function() {
			$.ajax({
				type: "POST",
				url: "/match-comment",	
				data: {content: $('#comment').val(), matchid: $('input[name="matchid"]').val()},
				success: function(data) {					
					switch (data) {
						case '0':
							GGSHOP.msgBox.show('ERROR', 'Please Login First   <a href="\/auth-login?preurl=\/match-index?matchid='+$('input[name="matchid"]').val()+'">Login >><\/a>');
							break;
						case '1':
							GGSHOP.msgBox.show('ERROR', 'Please Input Comments');
							break;
						case '2':
							GGSHOP.msgBox.show('ERROR', 'Success');
							GGSHOP.facematch.loadComment($('input[name="matchid"]').val());
							break;
						case '3':
							GGSHOP.msgBox.show('ERROR', 'Error');							
							break;
						default:
							alert('Error');
					}
				}			
			});
		},
		loadComment: function(matchId) {
			$.ajax({
				type: "get",
				url: "/facematch-getcomment?matchid="+matchId,					
				success: function(data) {					
					$('#list_comment').html(data);
				}			
			});
		},
		chipin: function(teamId, matchId) {
			GGSHOP.loading.show();
			$.ajax({
				type: "get",
				url: "/auth-userstatu",					
				success: function(data) {	
					GGSHOP.loading.hidden();
					if (data == 1) {
						GGSHOP.match.chipin(teamId, matchId);
					} else {
						GGSHOP.facematch.showLogin();
					}					
				}			
			});			
		},
		showLogin: function() {			
			$('#login').css({"left":($(window).width()-402)/2+"px", "top": $(document).scrollTop()+100, "z-index": 10002});
			$('#login').show();			
		},
		hide: function() {
			$('#login').hide();	
		}
};
GGSHOP.url = {
		redirect: function(link, page) {
			window.location.href= link+'page='+page;
		}
}

GGSHOP.exchange = {
		euros: function(obj) {
			$(obj).parent("div").css("display","none");
			$(obj).parent("div").next("div").css("display","");
		},
		usd: function(obj) {
			$(obj).parent("div").css("display","none");
			$(obj).parent("div").prev("div").css("display","");
		}
}

GGSHOP.hotsearchkeywords = {
		click: function(id) {

			$.ajax({

				type: "get",

				url: "/index-hotsearchclick?id="+id,					

				success: function(data) {					

					//

				}			

			});

		}
}

$(function(){
	var menu1 = $($('#mnavcat .w-lst a')[1]);
	menu1.hover(function(){
		$('#nav-nation-cate-id').hide();
		$('#nav-club-cate-id').slideDown('fast');
		menu1.addClass('cur2');
		$('#nav-club-cate-id').mouseover(function(){
			menu1.addClass('cur2');
			$(this).show();
		});
		$('#nav-club-cate-id').mouseout(function(){
			menu1.removeClass('cur2');
			$(this).hide();
		});
	},function(){
		menu1.removeClass('cur2');
		$('#nav-club-cate-id').hide();
	});
	var menu2 = $($('#mnavcat .w-lst a')[2]);
	menu2.hover(function(){
		$('#nav-nation-cate-id').slideDown('fast');
		$('#nav-club-cate-id').hide();
		menu2.addClass('cur2');
		$('#nav-nation-cate-id').mouseover(function(){
			menu2.addClass('cur2');
			$(this).show();
		});
		$('#nav-nation-cate-id').mouseout(function(){
			menu2.removeClass('cur2');
			$(this).hide();
		});
	},function(){
		menu2.removeClass('cur2');
		$('#nav-nation-cate-id').hide();
	});
	function toggleChooseCate(){
		$('#chooseCate .cmore a').toggle(function(){
			$(this).removeClass('down');
			$(this).addClass('up');
			var _div = $(this).parent().prev();
			$(this).attr('attrheight',_div.css('height'));
			_div.css('height','auto');
			return false;
		},function(){
			$(this).removeClass('up');
			$(this).addClass('down');
			var _div = $(this).parent().prev();
			_div.css('height',$(this).attr('attrheight'));
			return false;
		});
	}
	$('#ccateItem a').click(function(){
		var _flid = $(this).attr('flid');
		$('#filterItem').html('<div style="text-align:center;"><img style="margin:10px;" src="/images/loading.gif" /></div>');
		$(this).parent().parent().find('a').each(function(){
			$(this).removeClass('strong');
		});
		$(this).addClass('strong');
		$.ajax({
			type: "GET",
			url: "/category-showattrbyfid?cid="+_flid,
			success: function(data) {	
				$('#filterItem').html(data);
			}			
		});
		return false;
	});
	toggleChooseCate();
	if($('#commentsChanges .lcbd').length > 0){
		setInterval(function(){
			var lcbds = $('#commentsChanges .lcbd');
			var _len = lcbds.length;
			var _lcbdblk = $('#commentsChanges .lcbdblk');
			var _index = _lcbdblk.index();
			_index++;
			if(_index >= _len){
				_index = 0;
			}
			_lcbdblk.removeClass('lcbdblk');
			$(lcbds[_index]).addClass('lcbdblk');
			lcbds.hide();
			$(lcbds[_index]).fadeIn();
		},5000);
	}
	
	
});
